<template>
	<view class="page-pad">
		<mp-html :content="html" v-if="html" />
		<view class="pad-contd" v-else>
			<empty title="暂无数据"/>
		</view>
	</view>
</template>

<script>
	import {
		advertGetInfo,
		commonConfig
	} from 'utils/api/home.js'
	export default {
		data() {
			return {
				html: ''
			}
		},
		onLoad(data) {
			// 隐私协议和用户协议
			if(data.privacy) {
				this.getPrivacy(data.apiKey)
				return
			}
			if(data.id) {
				this.getInfo(data.id)
			} else {
				uni.setNavigationBarTitle({ title: data.title})
				this.html = uni.getStorageSync('htmlData')
			}
		},
		methods: {
			// 获取隐私协议和用户协议
			getPrivacy(key) {
				const title = {
					user_agreement: '用户协议',
					privacy_policy: '隐私政策'
				}
				uni.setNavigationBarTitle({ title: title[key]})
				uni.showLoading({
					title: '加载中'
				})
				commonConfig().then((res) => {
					this.html = res.data[key]
				}).finally(() => {
					uni.hideLoading()
				})
			},
			getInfo(id) {
				uni.showLoading({
					title: '加载中'
				})
				advertGetInfo({id}).then((res) => {
					this.html = res.data.content	
				}).finally(() => {
					uni.hideLoading()
				})
			}
		}
	}
</script>
<style  lang="scss">
.pad-contd {
	height: 100vh;
	display: flex;
	align-items: center;
	justify-content: center;
}
rich-text {
	line-height: 50upx !important;
}
</style>